﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Cost.Models;
using NBlock.MVCControl;
using NBlock.Components.Excel;
using NBlock.Core.ORM;
using System.Linq.Expressions;
using NBlock.Core;
using System.Data.SqlClient;

namespace Cost.Controllers
{
    public class MaterialPurchaseDetailController : Controller
    {
        private readonly ICostRepository<MaterialPurchaseItem> materialPurchaseItemRepository;
        private readonly IEnumService enumService;
        public MaterialPurchaseDetailController(ICostRepository<MaterialPurchaseItem> materialPurchaseItemRepository,
            IEnumService enumService)
        {
            this.materialPurchaseItemRepository = materialPurchaseItemRepository;
            this.enumService = enumService;
        }

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public JsonResult List(nbPageInfo pager, nbSearchCondition where)
        {
            var pageData = materialPurchaseItemRepository.GetPageable(pager, where);
            var data = pager.ToGridData(pageData);
            return Json(data);
        }

        [HttpPost]
        public JsonResult Tree(string Id)
        {
            var list = new List<JsonTreeNode>();
            if (string.IsNullOrWhiteSpace(Id))
            {
                // 获取供应商的数据
                list = enumService.GetEnumDataSource("Supplier")
                    .Select(t => new JsonTreeNode
                    {
                        id = t.Value,
                        text = t.Text,
                        value = t.Value
                    }).ToList();
            }
            return Json(list);
        }
    }

    public class SimpleMaterialPurchaseItem
    {
        public string MaterialId { get; set; }
        public string Name { get; set; }
        public decimal OrderCount { get; set; }
        public decimal StorageCount { get; set; }
    }
}
